package problem190;

//190.颠倒二进制位
//https://leetcode.cn/problems/reverse-bits/?envType=study-plan-v2&envId=top-interview-150

public class Solution {
    // you need treat n as an unsigned value
    public int reverseBits(int n) {
        long ret = 0, t = 1;
        for(int i = 0; i<=32; i++) {
            if((n & (1 << (32-i))) != 0) {
                ret += t/2;
            }
            t *= 2;
        }
        return (int)ret;
    }                                  
}